package com.example.service.impl;

import com.example.entity.Notice;
import com.example.entity.example.NoticeExample;
import com.example.mapper.NoticeMapper;
import com.example.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired(required = false)
    NoticeMapper noticeMapper;

    @Override
    public List<Notice> getAll() {
        return noticeMapper.selectByExample(new NoticeExample());
    }

    @Override
    public List<Notice> getByExampleWithLimit(String name, String title, String username, Integer curPage, Integer pageSize) {
        int begin = (curPage - 1) * pageSize;
        return noticeMapper.selectByExampleWithLimit(name, title, username, begin, pageSize);
    }

    @Override
    public int getCountByExample(String name, String title, String username) {
        return noticeMapper.getCountByExample(name, title, username);
    }

    @Override
    public Notice getById(Integer id) {
        return noticeMapper.selectByPrimaryKey(id);
    }

    @Override
    public void removeById(Integer id) {
        noticeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateSelectiveById(Notice notice) {
        noticeMapper.updateByPrimaryKeySelective(notice);
    }

    @Override
    public void addNotice(Notice notice) {
        noticeMapper.insert(notice);
    }
}
